<template>
	<div class="wrapper">
		<!-- header部分 -->
		<header>
			<p>商家注册</p>
		</header>
		<!-- 表单部分 -->
		<ul class="form-box">
			<li>
				<div class="title">
					商家名称：
				</div>
				<div class="content">
					<input type="text" v-model="businessName" placeholder="请输入商家名称">
				</div>
			</li>
			<li>
				<div class="title">
					商家地址：
				</div>
				<div class="content">
					<input type="text" v-model="businessAddress" placeholder="请输入商家地址">
				</div>
			</li>
			<li>
				<div class="title">
					商家介绍：
				</div>
				<div class="content">
					<input type="text" v-model="businessExplain" placeholder="请输入商家介绍">
				</div>
			</li>
			<li>
				<div class="title">
					分类：
				</div>
				<div class="content">
					<select v-model="orderTypeId">
						<option value="1">美食</option>
						<option value="2">早餐</option>
						<option value="3">鲜花</option>
						<option value="4">商超便利</option>
						<option value="5">汉堡披萨</option>
						<option value="6">甜品饮品</option>
						<option value="7">包子粥店</option>
						<option value="8">简餐</option>
					</select>
				</div>
			</li>
			<li>
				<div class="title">
					起送费：
				</div>
				<div class="content">
					<input type="number" v-model="starPrice" placeholder="请输入起送费" step="0.01" min="0">
				</div>
			</li>
			<li>
				<div class="title">
					配送费：
				</div>
				<div class="content">
					<input type="number" v-model="deliveryPrice" placeholder="请输入配送费" step="0.01" min="0">
				</div>
			</li>
			<li>
				<div class="title">
					备注：
				</div>
				<div class="content">
					<input type="text" v-model="remarks" placeholder="备注信息（可选）">
				</div>
			</li>
			<li>
				<div class="title">
					登录用户名：
				</div>
				<div class="content">
					<input type="text" v-model="businessUsername" placeholder="请输入登录用户名">
				</div>
			</li>
			<li>
				<div class="title">
					登录密码：
				</div>
				<div class="content">
					<input type="password" v-model="businessPassword" placeholder="请输入登录密码">
				</div>
			</li>
			<li>
				<div class="title">
					确认密码：
				</div>
				<div class="content">
					<input type="password" v-model="confirmPassword" placeholder="请再次输入密码">
				</div>
			</li>
		</ul>
		<div class="button-register">
			<button @click="register">注册</button>
		</div>
		<!-- 底部菜单部分 -->
		<Footer></Footer>
	</div>
</template>
<script>
 import Footer from '../components/Footer.vue';
 
 export default{
	name:'BusinessRegister',
	data(){
		return {
			businessName:'',
			businessAddress:'',
			businessExplain:'',
			businessImg:'',
			orderTypeId:'',
			starPrice:'',
			deliveryPrice:'',
			remarks:'',
			businessUsername:'',
			businessPassword:'',
			confirmPassword:''
		}
	},
	methods:{
		register(){
			if(this.businessName==''){
				alert('商家名称不能为空！');
				return;
			}
			if(this.businessAddress==''){
				alert('商家地址不能为空！');
				return;
			}
			if(this.businessExplain==''){
				alert('商家介绍不能为空！');
				return;
			}
			if(this.orderTypeId==''){
				alert('请选择商家分类！');
				return;
			}
			if(this.starPrice==''){
				alert('起送费不能为空！');
				return;
			}
			if(this.deliveryPrice==''){
				alert('配送费不能为空！');
				return;
			}
			if(this.businessUsername==''){
				alert('登录用户名不能为空！');
				return;
			}
			if(this.businessPassword==''){
				alert('登录密码不能为空！');
				return;
			}
			if(this.confirmPassword==''){
				alert('确认密码不能为空！');
				return;
			}
			if(this.businessPassword !== this.confirmPassword){
				alert('两次输入的密码不一致！');
				return;
			}
			
			//注册请求
			this.$axios.post('BusinessController/saveBusiness',this.$qs.stringify({
				businessName:this.businessName,
				businessAddress:this.businessAddress,
				businessExplain:this.businessExplain,
				businessImg:this.businessImg,
				orderTypeId:this.orderTypeId,
				starPrice:this.starPrice,
				deliveryPrice:this.deliveryPrice,
				remarks:this.remarks,
				businessUsername:this.businessUsername,
				businessPassword:this.businessPassword
			})).then(response=>{
				let result = response.data;
				if(result==1){
					alert('商家注册成功！');
					this.$router.push({path:'/login'});
				}else{
					alert('商家注册失败！');
				}
			}).catch(error=>{
				console.error(error);
			});
		},
	},
	components:{
		Footer
	}
 }
</script>
<style scoped>
	/****************** 总容器 ******************/
	.wrapper {
		width: 100%;
		height: 100%;
	}

	/****************** header部分 ******************/
	.wrapper header {
		width: 100%;
		height: 12vw;
		background-color: #0097FF;
		color: #fff;
		font-size: 4.8vw;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1000;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	/****************** 表单部分 ******************/
	.wrapper .form-box {
		width: 100%;
		margin-top: 12vw;
		padding-bottom: 15vw;
	}

	.wrapper .form-box li {
		box-sizing: border-box;
		padding: 4vw 3vw 0 3vw;
		display: flex;
		align-items: center;
	}

	.wrapper .form-box li .title {
		flex: 0 0 20vw;
		font-size: 3vw;
		font-weight: 700;
		color: #666;
	}

	.wrapper .form-box li .content {
		flex: 1;
	}

	.wrapper .form-box li .content input,
	.wrapper .form-box li .content select {
		border: none;
		outline: none;
		width: 100%;
		height: 6vw;
		font-size: 3vw;
		border-bottom: 1px solid #ddd;
		padding: 1vw 0;
		line-height: 4vw;
	}

	.wrapper .form-box li .content select {
		background-color: transparent;
	}

	.wrapper .button-register {
		width: 100%;
		box-sizing: border-box;
		padding: 4vw 3vw 0 3vw;
	}

	.wrapper .button-register button {
		width: 100%;
		height: 10vw;
		font-size: 3.8vw;
		font-weight: 700;
		color: #fff;
		background-color: #38CA73;
		border-radius: 4px;
		border: none;
		outline: none;
	}



</style> 